package com.easy.controller;

import com.easy.bean.Order;
import com.easy.service.IOrderService;
import com.easy.util.LayData;
import com.easy.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("order")
public class OrderController {
    @Autowired
    IOrderService orderService;
    @RequestMapping("add")
    @ResponseBody
    public LayData add(@RequestParam("id[]") List<Integer> id, @RequestParam("number[]")List<Integer> number, HttpSession session, @RequestParam("addressid") Integer addressid) {
        System.out.println(id);
        System.out.println(number);
        System.out.println(addressid);
        int userid= SYS.getLoginUserID(session);
        int orderid=orderService.addOrder(id,number,addressid,userid);
        return LayData.success(200,"订单创建成功",orderid);
    }


    @RequestMapping("payment")
    @ResponseBody
    public LayData payment(Integer id) {
        String code=orderService.payment(id);
        return LayData.success(200,"",code);
    }

    @RequestMapping("paymentsuccess")
    @ResponseBody
    public LayData paymentSuccess(@RequestParam HashMap map) {
        orderService.paymentSuccess(map);
        return LayData.success(200,"",map);
    }

    @RequestMapping("getorderstate")
    @ResponseBody
    public LayData getOrderState (@RequestParam("id") Integer id) {
        Order order = orderService.getOrderByID(id);
        return LayData.success(200,"",order.getState());
    }
}
